import { JSEncrypt } from 'jsencrypt';

export const encrypt = (password) => {
	// 公钥加密
	let publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCCHbwZCOhcm/pIyKXC1DO/Vdd56jOFBvZXzQaxmBk25OGPMJ2+bVS+/QWQ3oDZ6v1MUVTmI8gUXTcvdqdq7bJNiuX7qhL9UKFDKlEu8Um41BYXq8Eu4GByw91jHbLoVlTC8+6uZgFIuBY3ibPFgld0dBNle3IS4yQLBPeILYPqHQIDAQAB';
	const encrypt = new JSEncrypt();
	encrypt.setPublicKey(publicKey);
	let result = encrypt.encrypt(password);
	return result;
};

export function decrypt(txt) {
	//私钥解密
	const privateKey =
		'MIICWwIBAAKBgQCCHbwZCOhcm/pIyKXC1DO/Vdd56jOFBvZXzQaxmBk25OGPMJ2+bVS+/QWQ3oDZ6v1MUVTmI8gUXTcvdqdq7bJNiuX7qhL9UKFDKlEu8Um41BYXq8Eu4GByw91jHbLoVlTC8+6uZgFIuBY3ibPFgld0dBNle3IS4yQLBPeILYPqHQIDAQABAoGALTwpKIrwPUH8wVEAT7t2Qg6V2syRHK5O9jdRHGzEV1E7GYzNSma4D63nQXYZValcZivgWCIYbPv7M4UMrx/z3IFjpKX6A3Eecc8aycDRF/uLdvEjHrRSax42m9hEMG07bbnBewsouZcIndONWfqwOcqM/C4WmkVMTuH4Zkwl/AECQQDQoev0r2IvaGUmc7YhhYkBhiQeSKz1sEcpgxmnvkO12JwAmi+SMLVEaGIjinBMXHnzKU4Yg+rKplxTAQKk4dLHAkEAn6hO4aD7uUpzy6I58IsZY2wl7YmWgd3W6/OFsrgkElRMdx1AH6M4IPUmV0tWjwjFWUmn+ysvsTncMpmqKCK3+wJAbPPyllC09M8O69rHxY/H8bzMxefsM05Ai4REdJ5fG+sn5QSgTTcUosnkXm0gojA1G3B5sUHK7tOcKVjAubyY5wJAYWldh4ijTXBBqnL2iu8ztFed5IpYDDCAG0JfxqVXTN+mL97m6ua5LlKk7AoJbAfb8Rhhp3u4A5fb4/uhuA9G1QJACvObj4yvGIYz2DAU11R00NKtuQzKnwDhhtwJL9BIsJ1gBaz+rO56rjxHu6pJEQaNHCcjCvXoFxSlZpeRuE6UfA==';
	//使用私钥解密
	const decrypt = new JSEncrypt();
	decrypt.setPrivateKey(privateKey);
	let result = decrypt.decrypt(txt);
	return result;
}
